<template>
	<view class="star-contact">
		<view class="" v-if="list.length>0">
			<view class="txl-org-item border" v-for="(item, i) in list" :key="item.id" @click="chatPage(item)" @longpress="longtap(item, i)">
				<view class="logo-name">
					<image class="logo" :src="utils.headImage(item)" mode="aspectFill"></image>
					<view class="">
						<text class="name">{{item.name}}</text>
						<uni-icons customPrefix="iconfont" type="icon-biaoxingfill" color="#f59a23" size="32rpx"></uni-icons>
					</view>
				</view>
				<view v-if="item.type">
					<text :class="item.type==1?'type-tag-blue':'type-tag-orange'" class="type-tag">测试</text>
				</view>
			</view>
		</view>
		<view class="no-list" v-else>
			暂无星标联系人，可在右上角点击添加
		</view>
	</view>
</template>
<script>
export default {
	data() {
		return{
			list: [],
			accountIds: [],
			delIndex: -1
		} 
	},
	onShow() {
		uni.removeStorageSync('xdSelectAllInfo')
		this.getfindStarFriends()
	},
	onNavigationBarButtonTap(e){
		this.addStar()
	},
	methods: {
		chatPage(item){
			let userType = item.userType?item.userType:1
			let url = item.avatarUrl||'';
			uni.navigateTo({
				url: `/pages/chatSystem/chat-page?toUserType=${item.userType}&id=${item.id}&accountId=${item.accountId}&name=${item.name}&avatarUrl=${url}`
			})
		},
        addStar(){
            uni.navigateTo({
                url: '/pages/addressBook/add-star'
            })
        },
		getfindStarFriends(){
			this.api.get('mailList/findStarFriends').then(res=>{
				if(res.data.state != 'ok') return;
				let data = res.data;
				this.list = data.accountIdInfoList
			})
		},
		delStarFriends(){
			this.api.post('mailList/delStarFriends', {
				accountIds: JSON.stringify(this.accountIds)
			}).then(res=>{
				if(res.data.state!='ok') return;
				this.list.splice(this.delIndex, 1)
			})
		},
		longtap(item, i){
			this.delIndex = i
			this.accountIds.push(item.accountId)
			const platform = getApp().globalData.platform
			uni.showModal({
				title: '',
				content: '确定移除？',
				// #ifdef H5
				cancelText: '取消',
				confirmText: '移除',
				// #endif
				// #ifdef APP-PLUS
				cancelText: platform=='android'?'移除':'取消',
				confirmText: platform=='android'?'取消':'移除',
				// #endif
				success: (res) => {
					if (res.confirm) {
						// #ifndef APP-PLUS
						this.delStarFriends()
						// #endif
						// #ifdef APP-PLUS
						if(platform != 'android'){
							this.delStarFriends()
						}else{
							this.accountIds = [];
							this.delIndex = -1
						}
						// #endif
					} else if (res.cancel) {
						// #ifndef APP-PLUS
						this.accountIds = []
						this.delIndex = -1
						// #endif
						// #ifdef APP-PLUS
						if(platform == 'android'){
							this.delStarFriends()
						}else{
							this.accountIds = []
							this.delIndex = -1
						}
						// #endif
					}
				}
			});
		}
	}
}
</script>
<style lang="less" scoped>
	.border{
		position: relative;
		&::after{
			position: absolute;
			content: '';
			left: 88rpx;
			right: 0;
			bottom: 0;
			height: 2rpx;
			background: #f2f2f2;
		}
	}
	.name{
		margin-right: 10rpx;
	}
	.type-tag{
		display: inline-block;
		height: 40rpx;
		line-height: 40rpx;
		padding: 0 18rpx;
		
		border-radius: 10rpx;
		vertical-align: 6rpx;
		margin-left: 20rpx;
		font-size: 26rpx;
		white-space: nowrap;
		
	}
	.type-tag-orange{
		background-color: #f59a23;
		color: #fff;
	}
	.type-tag-blue {
		background-color: #81d3f8;
		color: #555;
	}
	.no-list{
		height: calc(100vh - 44px);
		display: flex;
		align-items: center;
		justify-content: center;
	}
</style>